home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / aros / source / exec / tasks / src / remtask.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-16  |  2.3 KB  |  103 lines

  1. /*
  2.     $Id: remtask.c 1.1 1995/12/17 21:37:10 digulla Exp digulla $
  3.     $Log: remtask.c $
  4.  * Revision 1.1  1995/12/17  21:37:10  digulla
  5.  * Initial revision
  6.  *
  7.     Desc:
  8.     Lang: english
  9. */
  10. #include "exec_intern.h"
  11. #include <exec/tasks.h>
  12.  
  13. /*****************************************************************************
  14.  
  15.     NAME */
  16.     #include <clib/exec_protos.h>
  17.  
  18.     __AROS_LH1(void, RemTask,
  19.  
  20. /*  SYNOPSIS */
  21.     __AROS_LA(struct Task *, task, A1),
  22.  
  23. /*  LOCATION */
  24.     struct ExecBase *, SysBase, 48, Exec)
  25.  
  26. /*  FUNCTION
  27.     Remove a task from the task lists. All memory in the tc_MemEntry list
  28.     is freed and a rescedule is done. It's safe to call RemTask() out
  29.     of Forbid() or Disable().
  30.     This function is one way to get rid of the current task. The other way
  31.     is to fall through the end of the entry point.
  32.  
  33.     INPUTS
  34.     task - Task to be removed. NULL means current task.
  35.  
  36.     RESULT
  37.  
  38.     NOTES
  39.  
  40.     EXAMPLE
  41.  
  42.     BUGS
  43.  
  44.     SEE ALSO
  45.     AddTask()
  46.  
  47.     INTERNALS
  48.  
  49.     HISTORY
  50.     29-10-95    digulla automatically created from
  51.                 exec_lib.fd and clib/exec_protos.h
  52.     17-12-95    digulla Incorporated code by Matthias Fleischner
  53.  
  54. *****************************************************************************/
  55. {
  56.     __AROS_FUNC_INIT
  57.     struct MemList *mb;
  58.  
  59.     /* A value of NULL means current task */
  60.     if(task==NULL)
  61.     task=SysBase->ThisTask;
  62.  
  63.     /*
  64.     Since it's possible that the following will free a task
  65.     structure that is used for some time afterwards it's
  66.     necessary to protect the free memory list so that nobody
  67.     can allocate that memory.
  68.     */
  69.     Forbid();
  70.  
  71.     /* Free all memory in the tc_MemEntry list. */
  72.     while((mb=(struct MemList *)RemHead(&task->tc_MemEntry))!=NULL)
  73.     /* Free one MemList node */
  74.     FreeEntry(mb);
  75.  
  76.     /* Changing the task lists always needs a Disable(). */
  77.     Disable();
  78.  
  79.     /* Freeing myself? */
  80.     if(task==SysBase->ThisTask)
  81.     {
  82.     /* Can't do that - let the dispatcher do it. */
  83.     task->tc_State=TS_REMOVED;
  84.  
  85.     /*
  86.         Since I don't know how many levels of Forbid()
  87.         are already pending I set a default value.
  88.     */
  89.     SysBase->TDNestCnt=-1;
  90.  
  91.     /* And force a task switch */
  92.     Switch();
  93.     /* Does not return. */
  94.     }else
  95.     /* Good luck. Freeing other tasks is simple. */
  96.     Remove(&task->tc_Node);
  97.  
  98.     /* All done. */
  99.     Enable();
  100.     Permit();
  101.     __AROS_FUNC_EXIT
  102. } /* RemTask */
  103.